package main

import (
	"fmt"
)

//定义接口
type Ainimal interface {
	sleeping()
	eating()
}

// interface{} 类似c语言的void

type Cat struct {
	color string
}

func (c Cat) sleeping() {
	fmt.Printf("%s's color cat is sleeping\n", c.color)
}

func (c Cat) eating() {
	fmt.Printf("%s's color cat is eating\n", c.color)
}

type Dog struct {
	color string
}

func (c Dog) sleeping() {
	fmt.Printf("%s's color dog is sleeping\n", c.color)
}

func (c Dog) eating() {
	fmt.Printf("%s's color dog is eating\n", c.color)
}

func sleeping(a Ainimal) {
	a.sleeping()
}

//自定义结构支持一个接口，要求实现接口内的全部方法

func main() {
	c1 := Cat{"white"}
	d1 := Dog{"black"}
	c1.eating()
	d1.eating()
	//感受多态
	var a1 Ainimal
	a1 = c1
	a1.sleeping()
	a1 = d1
	a1.sleeping()
	sleeping(d1)
	sleeping(c1)
}
